package com.ruoyi.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.domain.ZhwyChargeitem;
import com.ruoyi.domain.ZhwyChargeitemRentalcontract;
import com.ruoyi.service.IZhwyChargeitemService;
import com.ruoyi.service.ZhwyChargeItemContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * ClassName ZhwyChargeItemContractController
 * Description TODO
 * Author JunEr
 * Date 2024年05月09日 14:34
 * Version 1.0
 */
@RestController
@RequestMapping("/zxwy/ItemContract")
public class ZhwyChargeItemContractController extends BaseController {

    @Autowired
    private ZhwyChargeItemContractService service;
    @Autowired
    private IZhwyChargeitemService chargeItemService;

    @PostMapping("/remove")
    @Anonymous
    public AjaxResult remove(@RequestBody ZhwyChargeitemRentalcontract bean){
        return toAjax(service.removeByItemContract(bean));
    }
    @GetMapping("/alreadyAdd/{id}")
    @Anonymous
    public TableDataInfo alreadyAdd(@PathVariable("id") Long id){
        Long[] longs = service.listAll(id);
        if(longs==null||longs.length==0){
            return null;
        }
        List<ZhwyChargeitem> chargeItems = chargeItemService.notselectZhwyChargeitemListAll(longs);
        return getDataTable(chargeItems);
    }
    @GetMapping("/notAlreadyAdd/{id}")
    @Anonymous
    public TableDataInfo notAlreadyAdd(@PathVariable("id") Long id){
        Long[] longs = service.listAll(id);
        if(longs==null||longs.length==0){
            return null;
        }
        List<ZhwyChargeitem> chargeItems = chargeItemService.selectZhwyChargeitemListAll(longs);
        return getDataTable(chargeItems);
    }
}
